simple application
    gates:
        in: lowergate_in;
        in: uppergate_in;
        out: lowergate_out;
        out: uppergate_out;
endsimple

simple layer0
    gates:
        in: lowergate_in[];
        in: uppergate_in;
        out: lowergate_out[];
        out: uppergate_out;
endsimple

module sensornode
    parameters:
        CNNCTVTY: numeric,
        HEAD_DISTRIBUTION: numeric, //for random cluster head selection
        OCCUPATION: numeric,
        PX: numeric,
        PY: numeric,
        DISTANCE:numeric, //distance to the base
        ID: numeric,
        FATHER: numeric,
        SENSING_RADIUS: numeric,
        COMMUNICATION_RADIUS: numeric,
         POWER_SWITCH: bool;
    gates:
        in: in[];
        out: out[];
    submodules:
        sm_layer0: layer0;
            gatesizes:
                lowergate_in[CNNCTVTY],
                lowergate_out[CNNCTVTY];
            display: "p=230,282;i=block/process,blue";
        sm_application: application;
            display: "p=110,78;i=block/process,yellow";
    connections nocheck:
        for i=0..CNNCTVTY-1 do
            in[i] --> sm_layer0.lowergate_in[i];
            out[i] <-- sm_layer0.lowergate_out[i];
        endfor;
        sm_application.lowergate_in <-- sm_layer0.uppergate_out;
        sm_application.lowergate_out --> sm_layer0.uppergate_in;
    display: "b=402,477,rect;o=white";
endmodule


simple manager
    gates:
        in: in;
        out: out;
endsimple

module teen
    parameters:
        MAXCONN: numeric,
        NNODES: numeric,
        NODE_SENSING_RADIUS: numeric,
        NODE_COMMUNICATION_RADIUS: numeric,
        ZONE_X: numeric,
        ZONE_Y: numeric;
    submodules:
        sn: sensornode[NNODES];
            parameters:
                CNNCTVTY = MAXCONN,
                SENSING_RADIUS = NODE_SENSING_RADIUS,
                HEAD_DISTRIBUTION = 3,
                COMMUNICATION_RADIUS = NODE_COMMUNICATION_RADIUS,
                OCCUPATION = 2, //base = 5, cluster head = 1
                FATHER = 0,
                ID = 0,
                PX = 0,
                DISTANCE=1,
                PY = 0,
                POWER_SWITCH = 1;
            gatesizes:
                in[MAXCONN],
                out[MAXCONN];
        man: manager;
        
    connections nocheck:
    display: "p=0,0;b=800,600,rect;o=white";
endmodule

network TEEN : teen
endnetwork

